Viki Zygouras - 5/18/2020
!pip install colored
import chart_studio.plotly as py
import plotly.graph_objs as go
import plotly.figure_factory as ff
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from IPython.display import SVG, HTML
from scipy import stats
import plotly.io as pio
import plotly.express as px
from plotly import tools
from plotly.subplots import make_subplots
from statsmodels.stats.multicomp import pairwise_tukeyhsd
from statsmodels.stats.multicomp import MultiComparison
import itertools
import colored
import statsmodels.api as sm
from statsmodels.formula.api import ols
import statistics
from plotly.subplots import make_subplots
import plotly.graph_objects as go
Import the cleaned data:
reciprocity = pd.read_csv("ReciprocityAnalysis.csv")
#Captialize agent names
reciprocity['Agent'] = reciprocity['Agent'].str.capitalize()
colors = ['rgb(238,166,101)', 'rgb(238,199,188)', 'rgb(154,196,196)']
agents = [ 'Jibo', 'Alexa','Computer']
behavior = reciprocity
behaviors = ['Short Response', 'Mhm' , 'Answer Question',
'Follow-Up Question', 'Exclamation', 'Relevancy',
'Move Toward', 'Move Away', 'Touch' ,'Point', 'Shrug',
'Luring', 'Nod', 'Shake Head' , 'Tilt Head', 'Imitation', 'Imitation Dance',
'Generic Dance', 'Waving', 'Hand Gesture', 'Switch Eye Contact', 'Look Away',
'Glance at Others', 'Smile', 'Judgemental Eyebrow', 'Inquisitive Eyebrow',
'Downward Frown', 'Mouth Open', 'Whisper', 'Laugh', 'Thank You', 'Compliment',
'Defend', 'Insult', 'Judgemental Verbal', 'Angry Verbal', 'Interrupt']
#Will output one way ANOVA for all pairs of agents. Significant p-value results will be in purple.
def anova_oneway(dataframe1):
combinations = list(itertools.combinations(agents, 2)) #Creates all pairwise combinations of agents (i.e. Alexa & Jibo, etc)
print(colored.fg("black") + "One Way ANOVAs:")
for combo in combinations:
pvalString = ''
#run oneway anova here - will use the same dataframe passed in
oneway = stats.f_oneway(
dataframe1[(dataframe1["Agent"] == combo[0])].Proportion, #Take first agent in pair
dataframe1[(dataframe1["Agent"] == combo[1])].Proportion) #Take second agent in pair
pval = oneway[1]
#just for printing the purple significant p-vals
if pval < 0.05:
pvalString = colored.fg("magenta_3a") + str(pval)
else:
pvalString = colored.fg("black") + str(pval)
resultstr = colored.fg("black") + combo[0] + " vs. " + combo[1] + " P-Value: " + pvalString
print(resultstr)
#Plotly Express Histogram
fig = px.histogram(reciprocity, x="Description", color="Agent",barmode ='group', barnorm = 'fraction'
,color_discrete_sequence=colors).update_xaxes(categoryorder="total descending")
#Formatting
fig.update_layout(
legend_title_text='Agent',
yaxis_title='Proportion of Behaviors',
xaxis_title='Behavior',
title ='Engagement Across Agents' ,
width=1100, height=900,
xaxis=dict(type='category'),
plot_bgcolor = 'white',
boxmode = 'group')
fig.update_yaxes(gridcolor='#D3D3D3')
#fig.show()
temp = behavior
total = temp[["Family","Participant","Agent","Description", "Type"]]
total = total.groupby(['Participant','Agent', 'Description']).size().reset_index(name='counts')
combined = total.groupby('Participant')[['counts']].sum().reset_index()
allBehaviors = pd.merge(total, combined, on='Participant')
allBehaviors['Proportion'] = allBehaviors["counts_x"]/allBehaviors["counts_y"]
fig = go.Figure()
traces = []
#append each behavior to overall graph
for i in range(len(agents)):
currentTrace = go.Box(y=allBehaviors[allBehaviors['Agent'] == agents[i]].Proportion,x = allBehaviors['Description'],
name = agents[i], marker = dict(color = colors[i]))
traces.append(currentTrace)
fig.add_traces(traces)
fig.update_layout(
legend_title_text='Agent',
yaxis_title='Proportion of Behaviors',
xaxis_title='Behaviors',
title ='Voice-User Interface Agent Behaviors Grouped by Participant' ,
width=1500, height=700,
plot_bgcolor = 'white',
xaxis=dict(type='category'),
boxmode = 'group')
fig.update_yaxes(gridcolor='#D3D3D3')
#fig.show()
Test between adults and children across all behaviors:
#Make temp df
N = behavior
Nagent = N[["Family","Participant","Agent","Behavior", "isAdult", "isChild"]]
Nagent = Nagent.groupby(['Participant', 'Behavior', 'isAdult']).size().reset_index(name='counts')
totals = Nagent.groupby('Participant')[['counts']].sum().reset_index()
Nagent = pd.merge(Nagent, totals, on='Participant')
Nagent['Proportion'] = Nagent["counts_x"]/Nagent["counts_y"]
#Split by kids and adults
kids = Nagent[Nagent["isAdult"] == 0]
adults = Nagent[Nagent["isAdult"] == 1]
#Behavior Analysis: Adults vs. Children Overall Behavior
result = stats.f_oneway(kids.Proportion, adults.Proportion)
print("One Way ANOVA: \nChildren vs. Adults Across Behavior\n","P-Value:",result[1])
result
model = ols('Proportion ~ C(isAdult)', data=Nagent).fit()
anova_table = sm.stats.anova_lm(model, typ=2)
anova_table
N = behavior
Nagent = N[["Family","Participant","Agent","Behavior", "isAdult", "isChild"]]
Nagent = Nagent.groupby(['Participant', 'Agent', 'isAdult']).size().reset_index(name='counts')
totals = Nagent.groupby('Participant')[['counts']].sum().reset_index()
Nagent = pd.merge(Nagent, totals, on='Participant')
Nagent['Proportion'] = Nagent["counts_x"]/Nagent["counts_y"]
#Split by kids and adults
kids = Nagent[Nagent["isAdult"] == 0]
adults = Nagent[Nagent["isAdult"] == 1]
#Behavior Analysis: Adults vs. Children Overall Behavior
result = stats.f_oneway(kids.Proportion, adults.Proportion)
print("One Way ANOVA:\nChildren vs. Adults Across Agents\n","P-Value:",result[1])
#Data for plot below: make a copy of a subset of the df
pos = behavior[["Family","Participant","Agent","Description", "Positive", "Type"]]
#Group by participant and calculate proportions
pos = pos.groupby([ "Participant", 'Agent', 'Positive']).size().reset_index(name='counts')
totals = pos.groupby("Participant")[['counts']].sum().reset_index()
pos = pd.merge(pos, totals, on="Participant")
pos['Proportion'] = pos["counts_x"]/pos["counts_y"]
#Want to isolate the positive values
neg = pos[pos['Positive'] == 0]
pos = pos[pos['Positive'] == 1]
#Plot the positive behavior data
positiveFigure = go.Figure()
#Create a box for each agent and append to overall plot - adapted & modified from previous notebooks
traces = []
for i in range(len(agents)):
positive = go.Box(y=pos[pos["Agent"] == agents[i]].Proportion, name = "<b>Positive</b>", marker = dict(color = colors[i]),
showlegend = False)
nonverb = go.Box(y=neg[neg["Agent"] == agents[i]].Proportion, name = "<b>Not Positive</b>", marker = dict(color = colors[i]),
showlegend=False)
traces.append(positive)
traces.append(nonverb)
positiveFigure.add_traces(traces)
positiveFigure.update_layout(
title_text ='<b>Sentiment of User Response</b>' ,
width=800, height=800,
plot_bgcolor = 'white',
boxmode = 'group',
font=dict(
size=20,
color="#000000",
family="Calibri, Body",)
)
positiveFigure.update_yaxes(gridcolor='#D3D3D3')
positiveFigure.update(layout=dict(title=dict(x=0.5)))
positiveFigure.show()
positiveFigure.write_image("images/sentiment.svg")
One Way ANOVAs for Positive and Not Positive:
#across the three agents - positive
stats.f_oneway(pos[(pos["Agent"] == "Jibo")].Proportion,pos[(pos["Agent"] == "Computer")].Proportion,pos[(pos["Agent"] == "Alexa")].Proportion)
#across the three agents - negative
stats.f_oneway(neg[(neg["Agent"] == "Jibo")].Proportion,neg[(neg["Agent"] == "Computer")].Proportion,neg[(neg["Agent"] == "Alexa")].Proportion)
print("Positive: \n")
anova_oneway(pos)
print("\nNot Positive: \n")
anova_oneway(neg)
model = ols('Proportion ~ C(Agent)', data=neg).fit()
anova_table = sm.stats.anova_lm(model, typ=2)
anova_table
MultiComp = MultiComparison(pos['Proportion'],pos["Agent"])
print(MultiComp.tukeyhsd().summary())
MultiComp = MultiComparison(neg['Proportion'],neg["Agent"])
print(MultiComp.tukeyhsd().summary())
print('Computer: ', statistics.mean(pos[(pos["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.mean(pos[(pos["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.mean(pos[(pos["Agent"] == "Alexa")].Proportion))
print('Computer: ', statistics.stdev(pos[(pos["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.stdev(pos[(pos["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.stdev(pos[(pos["Agent"] == "Alexa")].Proportion))
verbal = behavior[["Family","Participant","Agent","Description", "Positive", "Verbal" ,"Type"]]
#Group by participant and calculate proportions
verbal = verbal.groupby([ "Participant", 'Agent', 'Verbal']).size().reset_index(name='counts')
totals = verbal.groupby("Participant")[['counts']].sum().reset_index()
verbal = pd.merge(verbal, totals, on="Participant")
verbal['Proportion'] = verbal["counts_x"]/verbal["counts_y"]
#Want to isolate the positive values
nonverbal = verbal[verbal['Verbal'] == 0]
verbal = verbal[verbal['Verbal'] == 1]
verbalFigure = go.Figure()
#Create a box for each agent and append to overall plot - adapted & modified from previous notebooks
traces = []
for i in range(len(agents)):
current = go.Box(y=verbal[verbal["Agent"] == agents[i]].Proportion, name = "<b>Verbal</b>", marker = dict(color = colors[i]),
showlegend = False)
nonverb = go.Box(y=nonverbal[nonverbal["Agent"] == agents[i]].Proportion, name = "<b>Nonverbal</b>", marker = dict(color = colors[i]),
showlegend=False)
traces.append(current)
traces.append(nonverb)
verbalFigure.add_traces(traces)
verbalFigure.update_layout(
title_text ='<b>Verbal and Nonverbal User Response</b>' ,
width=800, height=800,
plot_bgcolor = 'white',
boxmode = 'group',
font=dict(
size=20,
color="#000000",
family="Calibri, Body",)
)
verbalFigure.update_yaxes(gridcolor='#D3D3D3')
verbalFigure.update(layout=dict(title=dict(x=0.5)))
verbalFigure.show()
verbalFigure.write_image("images/verbal.svg")
#across the three agents - verbal
stats.f_oneway(verbal[(verbal["Agent"] == "Jibo")].Proportion,verbal[(verbal["Agent"] == "Computer")].Proportion,verbal[(verbal["Agent"] == "Alexa")].Proportion)
#across the three agents - nonverbal
stats.f_oneway(nonverbal[(nonverbal["Agent"] == "Jibo")].Proportion,nonverbal[(nonverbal["Agent"] == "Computer")].Proportion,nonverbal[(nonverbal["Agent"] == "Alexa")].Proportion)
#model for verbal
model = ols('Proportion ~ C(Agent)', data=verbal).fit()
anova_table = sm.stats.anova_lm(model, typ=2)
anova_table
#model for nonverbal
model = ols('Proportion ~ C(Agent)', data=nonverbal).fit()
anova_table = sm.stats.anova_lm(model, typ=2)
anova_table
print("Verbal")
anova_oneway(verbal)
print("\nNonVerbal")
anova_oneway(nonverbal)
MultiComp = MultiComparison(verbal['Proportion'],verbal["Agent"])
print(MultiComp.tukeyhsd().summary())
MultiComp = MultiComparison(nonverbal['Proportion'],nonverbal["Agent"])
print(MultiComp.tukeyhsd().summary())
print('Computer: ', statistics.mean(verbal[(verbal["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.mean(verbal[(verbal["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.mean(verbal[(verbal["Agent"] == "Alexa")].Proportion))
print('Computer: ', statistics.stdev(verbal[(verbal["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.stdev(verbal[(verbal["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.stdev(verbal[(verbal["Agent"] == "Alexa")].Proportion))
print('Computer: ', statistics.mean(nonverbal[(nonverbal["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.mean(nonverbal[(nonverbal["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.mean(nonverbal[(nonverbal["Agent"] == "Alexa")].Proportion))
print('Computer: ', statistics.stdev(nonverbal[(nonverbal["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.stdev(nonverbal[(nonverbal["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.stdev(nonverbal[(nonverbal["Agent"] == "Alexa")].Proportion))
#Data for plot below: make a copy of a subset of the df
verbal = behavior[["Family","Participant","Agent","Description", "Positive", "Positive Verbal", "Type"]]
#Group by participant and calculate proportions
verbal = verbal.groupby([ "Participant", 'Agent', 'Positive', "Positive Verbal"]).size().reset_index(name='counts')
totals = verbal.groupby("Participant")[['counts']].sum().reset_index()
verbal = pd.merge(verbal, totals, on="Participant")
verbal['Proportion'] = verbal["counts_x"]/verbal["counts_y"]
#Want to isolate the positive values
posVerbal = verbal[verbal['Positive Verbal'] == 1]
neg = posVerbal[posVerbal['Positive'] == 0]
pos = posVerbal[posVerbal['Positive'] == 1]
#Plot the positive behavior data
fig = go.Figure()
#Create a box for each agent and append to overall plot - adapted & modified from previous notebooks
traces = []
for i in range(len(agents)):
current = go.Box(y=pos[pos["Agent"] == agents[i]].Proportion, name = "Actual Positive", marker = dict(color = colors[i]),
showlegend = False)
nonverb = go.Box(y=neg[neg["Agent"] == agents[i]].Proportion, name = "Not Positive", marker = dict(color = colors[i]),
showlegend=False)
traces.append(current)
traces.append(nonverb)
fig.add_traces(traces)
fig.update_layout(
legend_title_text='Agent',
yaxis_title='Proportion of Behaviors',
xaxis_title='Agent',
title ='Positive Verbal Category Across Behaviors' ,
width=800, height=600,
plot_bgcolor = 'white',
boxmode = 'group')
fig.update_yaxes(gridcolor='#D3D3D3')
fig.show()
print("Positive Verbal: Positive")
anova_oneway(pos)
print("\nPositive Verbal: Not Postive")
anova_oneway(neg)
pos = behavior[["Family","Participant","Agent","Description", "Positive", "Acknowledgement Verbal","Negative Verbal" , "Positive Verbal","Head", "Hand", "Face", "Eye", "Body"]]
#Group by participant and calculate proportions
pos = pos.groupby([ "Participant", 'Agent', "Positive" ,"Head", "Hand", "Face", "Eye", "Body", "Acknowledgement Verbal", "Positive Verbal", "Negative Verbal"]).size().reset_index(name='counts')
totals = pos.groupby("Participant")[['counts']].sum().reset_index()
pos = pd.merge(pos, totals, on="Participant")
pos['Proportion'] = pos["counts_x"]/pos["counts_y"]
#Want to isolate the positive values of each category
hand = pos[pos['Hand'] == 1]
head = pos[pos['Head'] == 1]
body = pos[pos['Body'] == 1]
eye = pos[pos['Eye'] == 1]
posverb = pos[pos["Positive Verbal"] == 1]
ack = pos[pos["Acknowledgement Verbal"] == 1]
negV = pos[pos["Negative Verbal" ] == 1]
fig = go.Figure()
#Create a box for each agent and append to overall plot - adapted & modified from previous notebooks
traces = []
for i in range(len(agents)):
current = go.Box(y=hand[hand["Agent"] == agents[i]].Proportion, name = "Hand", marker = dict(color = colors[i]),
showlegend = False)
nonverb = go.Box(y=head[head["Agent"] == agents[i]].Proportion, name = "Head", marker = dict(color = colors[i]),
showlegend=False)
bod = go.Box(y=body[body["Agent"] == agents[i]].Proportion, name = "Body", marker = dict(color = colors[i]),
showlegend=False)
ey = go.Box(y=eye[eye["Agent"] == agents[i]].Proportion, name = "Eye", marker = dict(color = colors[i]),
showlegend=False)
pv = go.Box(y=posverb[posverb["Agent"] == agents[i]].Proportion, name = "Positive Verbal", marker = dict(color = colors[i]),
showlegend=False)
ackno = go.Box(y=ack[ack["Agent"] == agents[i]].Proportion, name = "Acknowledgement Verbal", marker = dict(color = colors[i]),
showlegend=False)
negative = go.Box(y=negV[negV["Agent"] == agents[i]].Proportion, name = "Negative Verbal", marker = dict(color = colors[i]),
showlegend=False)
traces.append(current)
traces.append(nonverb)
traces.append(bod)
traces.append(ey)
traces.append(pv)
traces.append(ackno)
traces.append(negative)
fig.add_traces(traces)
fig.update_layout(
legend_title_text='Agent',
yaxis_title='Proportion of Behaviors',
xaxis_title='Agent',
title ='All Behaviors Split by Categories' ,
width=800, height=800,
plot_bgcolor = 'white',
boxmode = 'group',
boxgap = 0.0001,
boxgroupgap = 0.001)
dfs = [body, eye, posverb,ack,negV, hand, head]
labels = ["Body", "Eye", "Positive Verbal", "ack", "Negative Verbal", "Hand", "Head"]
#Isolate the positive values for each agent
for i in range(len(dfs)):
print( "\n" +labels[i].capitalize() )
anova_oneway(dfs[i])
fig.update_yaxes(gridcolor='#D3D3D3')
fig.show()
pos = behavior[["Family","Participant","Agent","Description", "Positive", "Acknowledgement Verbal","Negative Verbal" , "Positive Verbal","Head", "Hand", "Face", "Eye", "Body"]]
#Group by participant and calculate proportions
pos = pos.groupby([ "Participant", 'Agent', "Positive" ,"Head", "Hand", "Face", "Eye", "Body", "Acknowledgement Verbal", "Positive Verbal", "Negative Verbal"]).size().reset_index(name='counts')
totals = pos.groupby("Participant")[['counts']].sum().reset_index()
pos = pd.merge(pos, totals, on="Participant")
pos['Proportion'] = pos["counts_x"]/pos["counts_y"]
#Want to isolate the positive values
pos = pos[pos['Positive'] == 1]
hand = pos[pos['Hand'] == 1]
head = pos[pos['Head'] == 1]
body = pos[pos['Body'] == 1]
eye = pos[pos['Eye'] == 1]
posverb = pos[pos["Positive Verbal"] == 1]
ack = pos[pos["Acknowledgement Verbal"] == 1]
negV = pos[pos["Negative Verbal" ] == 1]
fig = go.Figure()
#Create a box for each agent and append to overall plot - adapted & modified from previous notebooks
traces = []
for i in range(len(agents)):
current = go.Box(y=hand[hand["Agent"] == agents[i]].Proportion, name = "Hand", marker = dict(color = colors[i]),
showlegend = False)
nonverb = go.Box(y=head[head["Agent"] == agents[i]].Proportion, name = "Head", marker = dict(color = colors[i]),
showlegend=False)
bod = go.Box(y=body[body["Agent"] == agents[i]].Proportion, name = "Body", marker = dict(color = colors[i]),
showlegend=False)
ey = go.Box(y=eye[eye["Agent"] == agents[i]].Proportion, name = "Eye", marker = dict(color = colors[i]),
showlegend=False)
pv = go.Box(y=posverb[posverb["Agent"] == agents[i]].Proportion, name = "Positive Verbal", marker = dict(color = colors[i]),
showlegend=False)
ackno = go.Box(y=ack[ack["Agent"] == agents[i]].Proportion, name = "Acknowledgement Verbal", marker = dict(color = colors[i]),
showlegend=False)
negative = go.Box(y=negV[negV["Agent"] == agents[i]].Proportion, name = "Negative Verbal", marker = dict(color = colors[i]),
showlegend=False)
traces.append(current)
traces.append(nonverb)
traces.append(bod)
traces.append(ey)
traces.append(pv)
traces.append(ackno)
traces.append(negative)
fig.add_traces(traces)
fig.update_layout(
legend_title_text='Agent',
yaxis_title='Proportion of Behaviors',
xaxis_title='Agent',
title ='Positive Behaviors Split by Categories' ,
width=800, height=800,
plot_bgcolor = 'white',
boxmode = 'group',
boxgap = 0.0001,
boxgroupgap = 0.001)
dfs = [body, eye, posverb,ack,negV, hand, head]
labels = ["Body", "Eye", "Positive Verbal", "ack", "Negative Verbal", "Hand", "Head"]
#Isolate the positive values for each agent
for i in range(len(dfs)):
print( "\n" +labels[i].capitalize() )
anova_oneway(dfs[i])
fig.update_yaxes(gridcolor='#D3D3D3')
fig.show()
pos = behavior[["Family","Participant","Agent","Description", "Positive", "Acknowledgement Verbal","Negative Verbal" , "Positive Verbal","Head", "Hand", "Face", "Eye", "Body"]]
#Group by participant and calculate proportions
pos = pos.groupby([ "Participant", 'Agent', "Positive" ,"Head", "Hand", "Face", "Eye", "Body", "Acknowledgement Verbal", "Positive Verbal", "Negative Verbal"]).size().reset_index(name='counts')
totals = pos.groupby("Participant")[['counts']].sum().reset_index()
pos = pd.merge(pos, totals, on="Participant")
pos['Proportion'] = pos["counts_x"]/pos["counts_y"]
#Want to isolate the positive values
pos = pos[pos['Positive'] == 0]
hand = pos[pos['Hand'] == 1]
head = pos[pos['Head'] == 1]
body = pos[pos['Body'] == 1]
eye = pos[pos['Eye'] == 1]
posverb = pos[pos["Positive Verbal"] == 1]
ack = pos[pos["Acknowledgement Verbal"] == 1]
negV = pos[pos["Negative Verbal" ] == 1]
fig = go.Figure()
#Create a box for each agent and append to overall plot - adapted & modified from previous notebooks
traces = []
for i in range(len(agents)):
current = go.Box(y=hand[hand["Agent"] == agents[i]].Proportion, name = "Hand", marker = dict(color = colors[i]),
showlegend = False)
nonverb = go.Box(y=head[head["Agent"] == agents[i]].Proportion, name = "Head", marker = dict(color = colors[i]),
showlegend=False)
bod = go.Box(y=body[body["Agent"] == agents[i]].Proportion, name = "Body", marker = dict(color = colors[i]),
showlegend=False)
ey = go.Box(y=eye[eye["Agent"] == agents[i]].Proportion, name = "Eye", marker = dict(color = colors[i]),
showlegend=False)
pv = go.Box(y=posverb[posverb["Agent"] == agents[i]].Proportion, name = "Positive Verbal", marker = dict(color = colors[i]),
showlegend=False)
ackno = go.Box(y=ack[ack["Agent"] == agents[i]].Proportion, name = "Acknowledgement Verbal", marker = dict(color = colors[i]),
showlegend=False)
negative = go.Box(y=negV[negV["Agent"] == agents[i]].Proportion, name = "Negative Verbal", marker = dict(color = colors[i]),
showlegend=False)
traces.append(current)
traces.append(nonverb)
traces.append(bod)
traces.append(ey)
traces.append(pv)
traces.append(ackno)
traces.append(negative)
fig.add_traces(traces)
fig.update_layout(
legend_title_text='Agent',
yaxis_title='Proportion of Behaviors',
xaxis_title='Agent',
title ='Not Positive Behaviors Split by Categories' ,
width=800, height=800,
plot_bgcolor = 'white',
boxmode = 'group',
boxgap = 0.0001,
boxgroupgap = 0.001)
dfs = [body, eye, posverb,ack,negV, hand, head]
labels = ["body", "eye", "posverb", "ack", "negV", "hand", "head"]
#Isolate the positive values for each agent
for i in range(len(dfs)):
print(labels[i].capitalize())
anova_oneway(dfs[i])
fig.update_yaxes(gridcolor='#D3D3D3')
fig.show()
pos = behavior[["Participant", "Family","InSync","Agent","Description", "Acknowledgement Verbal","Negative Verbal" , "Positive Verbal","Head", "Hand", "Face", "Eye", "Body"]]
#Group by participant and calculate proportions
pos = pos.groupby([ "Participant", 'Agent', "InSync" ,"Head", "Hand", "Face", "Eye", "Body", "Acknowledgement Verbal", "Positive Verbal", "Negative Verbal"]).size().reset_index(name='counts')
totals = pos.groupby("Participant")[['counts']].sum().reset_index()
pos = pd.merge(pos, totals, on="Participant")
pos['Proportion'] = pos["counts_x"]/pos["counts_y"]
#Want to isolate the positive values
pos = pos[pos['InSync'] == 1]
hand = pos[pos['Hand'] == 1]
head = pos[pos['Head'] == 1]
body = pos[pos['Body'] == 1]
eye = pos[pos['Eye'] == 1]
posverb = pos[pos["Positive Verbal"] == 1]
ack = pos[pos["Acknowledgement Verbal"] == 1]
negV = pos[pos["Negative Verbal" ] == 1]
fig = go.Figure()
#Create a box for each agent and append to overall plot - adapted & modified from previous notebooks
traces = []
for i in range(len(agents)):
current = go.Box(y=hand[hand["Agent"] == agents[i]].Proportion, name = "Hand", marker = dict(color = colors[i]),
showlegend = False)
nonverb = go.Box(y=head[head["Agent"] == agents[i]].Proportion, name = "Head", marker = dict(color = colors[i]),
showlegend=False)
bod = go.Box(y=body[body["Agent"] == agents[i]].Proportion, name = "Body", marker = dict(color = colors[i]),
showlegend=False)
ey = go.Box(y=eye[eye["Agent"] == agents[i]].Proportion, name = "Eye", marker = dict(color = colors[i]),
showlegend=False)
pv = go.Box(y=posverb[posverb["Agent"] == agents[i]].Proportion, name = "Positive Verbal", marker = dict(color = colors[i]),
showlegend=False)
ackno = go.Box(y=ack[ack["Agent"] == agents[i]].Proportion, name = "Acknowledgement Verbal", marker = dict(color = colors[i]),
showlegend=False)
negative = go.Box(y=negV[negV["Agent"] == agents[i]].Proportion, name = "Negative Verbal", marker = dict(color = colors[i]),
showlegend=False)
traces.append(current)
traces.append(nonverb)
traces.append(bod)
traces.append(ey)
traces.append(pv)
traces.append(ackno)
traces.append(negative)
fig.add_traces(traces)
fig.update_layout(
legend_title_text='Agent',
yaxis_title='Proportion of Behaviors',
xaxis_title='Agent',
title ='In Sync Behaviors Split by Categories' ,
width=800, height=800,
plot_bgcolor = 'white',
boxmode = 'group',
boxgap = 0.0001,
boxgroupgap = 0.001)
dfs = [body, eye, posverb,ack,negV, hand, head]
labels = ["body", "eye", "posverb", "ack", "negV", "hand", "head"]
#Isolate the positive values for each agent
for i in range(len(dfs)):
print(labels[i].capitalize())
anova_oneway(dfs[i])
fig.update_yaxes(gridcolor='#D3D3D3')
fig.show()
pos = behavior[["Participant", "Family","InSync","Agent","Description", "Acknowledgement Verbal","Negative Verbal" , "Positive Verbal","Head", "Hand", "Face", "Eye", "Body"]]
#Group by participant and calculate proportions
pos = pos.groupby([ "Participant", 'Agent', "InSync" ,"Head", "Hand", "Face", "Eye", "Body", "Acknowledgement Verbal", "Positive Verbal", "Negative Verbal"]).size().reset_index(name='counts')
totals = pos.groupby("Participant")[['counts']].sum().reset_index()
pos = pd.merge(pos, totals, on="Participant")
pos['Proportion'] = pos["counts_x"]/pos["counts_y"]
#Want to isolate the positive values
pos = pos[pos['InSync'] == 0]
hand = pos[pos['Hand'] == 1]
head = pos[pos['Head'] == 1]
body = pos[pos['Body'] == 1]
eye = pos[pos['Eye'] == 1]
posverb = pos[pos["Positive Verbal"] == 1]
ack = pos[pos["Acknowledgement Verbal"] == 1]
negV = pos[pos["Negative Verbal" ] == 1]
fig = go.Figure()
#Create a box for each agent and append to overall plot - adapted & modified from previous notebooks
traces = []
for i in range(len(agents)):
current = go.Box(y=hand[hand["Agent"] == agents[i]].Proportion, name = "Hand", marker = dict(color = colors[i]),
showlegend = False)
nonverb = go.Box(y=head[head["Agent"] == agents[i]].Proportion, name = "Head", marker = dict(color = colors[i]),
showlegend=False)
bod = go.Box(y=body[body["Agent"] == agents[i]].Proportion, name = "Body", marker = dict(color = colors[i]),
showlegend=False)
ey = go.Box(y=eye[eye["Agent"] == agents[i]].Proportion, name = "Eye", marker = dict(color = colors[i]),
showlegend=False)
pv = go.Box(y=posverb[posverb["Agent"] == agents[i]].Proportion, name = "Positive Verbal", marker = dict(color = colors[i]),
showlegend=False)
ackno = go.Box(y=ack[ack["Agent"] == agents[i]].Proportion, name = "Acknowledgement Verbal", marker = dict(color = colors[i]),
showlegend=False)
negative = go.Box(y=negV[negV["Agent"] == agents[i]].Proportion, name = "Negative Verbal", marker = dict(color = colors[i]),
showlegend=False)
traces.append(current)
traces.append(nonverb)
traces.append(bod)
traces.append(ey)
traces.append(pv)
traces.append(ackno)
traces.append(negative)
fig.add_traces(traces)
fig.update_layout(
legend_title_text='Agent',
yaxis_title='Proportion of Behaviors',
xaxis_title='Agent',
title ='Mismatch Behaviors Split by Categories' ,
width=800, height=800,
plot_bgcolor = 'white',
boxmode = 'group',
boxgap = 0.0001,
boxgroupgap = 0.001)
dfs = [body, eye, posverb,ack,negV, hand, head]
labels = ["body", "eye", "posverb", "ack", "negV", "hand", "head"]
#Isolate the positive values for each agent
for i in range(len(dfs)):
print(labels[i].capitalize())
anova_oneway(dfs[i])
fig.update_yaxes(gridcolor='#D3D3D3')
fig.show()
sync = behavior[["Family","Participant","Agent","Description", "InSync", "Type"]]
#Group by participant and calculate proportions
sync = sync.groupby([ "Participant", 'Agent', 'InSync']).size().reset_index(name='counts')
totals = sync.groupby("Participant")[['counts']].sum().reset_index()
sync = pd.merge(sync, totals, on="Participant")
sync['Proportion'] = sync["counts_x"]/sync["counts_y"]
#Want to isolate the positive values
mismatch = sync[sync['InSync'] == 0]
sync = sync[sync['InSync'] == 1]
syncFigure = go.FigureWidget()
#Create a box for each agent and append to overall plot - adapted & modified from previous notebooks
syncTraces = []
for i in range(len(agents)):
current = go.Box(y=sync[sync["Agent"] == agents[i]].Proportion, name = "<b>In-Sync</b>", marker = dict(color = colors[i]),
showlegend = False)
mismatched = go.Box(y=mismatch[mismatch["Agent"] == agents[i]].Proportion, name = "<b>Mismatch</b>", marker = dict(color = colors[i]),
showlegend=False)
syncTraces.append(current)
syncTraces.append(mismatched)
syncFigure.add_traces(syncTraces)
syncFigure.update_layout(
legend_title_text='Agent',
title_text ='<b>Synchrony of Agent and User Sentiment</b>' ,
width=800, height=800,
plot_bgcolor = 'white',
boxmode = 'group',
font=dict(
size=20,
color="#000000",
family="Calibri, Body",)
)
syncFigure.update_yaxes(gridcolor='#D3D3D3')
syncFigure.update(layout=dict(title=dict(x=0.5)))
syncFigure.show()
syncFigure.write_image("images/sync.svg")
#across the three agents - sync
stats.f_oneway(sync[(sync["Agent"] == "Jibo")].Proportion,sync[(sync["Agent"] == "Computer")].Proportion,sync[(sync["Agent"] == "Alexa")].Proportion)
#across the three agents - mismatch
stats.f_oneway(mismatch[(mismatch["Agent"] == "Jibo")].Proportion,mismatch[(mismatch["Agent"] == "Computer")].Proportion,mismatch[(mismatch["Agent"] == "Alexa")].Proportion)
#model for sync
model = ols('Proportion ~ C(Agent)', data=sync).fit()
anova_table = sm.stats.anova_lm(model, typ=2)
anova_table
#model for mismatch
model = ols('Proportion ~ C(Agent)', data=mismatch).fit()
anova_table = sm.stats.anova_lm(model, typ=2)
anova_table
anova_oneway(sync)
anova_oneway(mismatch)
MultiComp = MultiComparison(sync['Proportion'],sync["Agent"])
print(MultiComp.tukeyhsd().summary())
MultiComp = MultiComparison(mismatch['Proportion'],mismatch["Agent"])
print(MultiComp.tukeyhsd().summary())
print('Computer: ', statistics.mean(sync[(sync["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.mean(sync[(sync["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.mean(sync[(sync["Agent"] == "Alexa")].Proportion))
print('Computer: ', statistics.stdev(sync[(sync["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.stdev(sync[(sync["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.stdev(sync[(sync["Agent"] == "Alexa")].Proportion))
#Group all behaviors as either positive, notpositive, mismatch, or insync
temp = behavior
total = temp[["Participant","Agent","Description", "Positive", "InSync" ]]
total = total.groupby(['Participant','Agent', 'Description', "Positive", "InSync"]).size().reset_index(name='counts')
combined = total.groupby('Participant')[['counts']].sum().reset_index()
allBehaviors = pd.merge(total, combined, on='Participant')
allBehaviors['Proportion'] = allBehaviors["counts_x"]/allBehaviors["counts_y"]
allBehaviorsP = allBehaviors[allBehaviors['Positive'] == 1]
allBehaviorsN = allBehaviors[allBehaviors['Positive'] == 0]
allBehaviorsM = allBehaviors[allBehaviors['InSync'] == 0]
allBehaviorsS= allBehaviors[allBehaviors['InSync'] == 1]
#Isolate the data for each behavior and make its own sub-df to prepare for plotting
#Categories
singleBehaviorDFsP = []
singleBehaviorDFsN = []
singleBehaviorDFs = []
singleBehaviorDFsM = []
singleBehaviorDFsS = []
for behavior in behaviors:
tempP = allBehaviorsP
tempN = allBehaviorsN
tempM = allBehaviorsM
tempS = allBehaviorsS
tempAll = allBehaviors
tempP = tempP[tempP['Description']==behavior]
singleBehaviorDFsP.append(tempP)
tempN = tempN[tempN['Description']==behavior]
singleBehaviorDFsN.append(tempN)
tempS = tempS[tempS['Description']==behavior]
singleBehaviorDFsS.append(tempS)
tempM = tempM[tempM['Description']==behavior]
singleBehaviorDFsM.append(tempM)
tempAll = tempAll[tempAll['Description']==behavior]
singleBehaviorDFs.append(tempAll)
#Will plot one behavior individually
def makeBoxplot(df, behavior):
fig = go.Figure()
traces = []
for i in range(len(agents)):
currentTrace = go.Box(y=df[df['Agent'] == agents[i]].Proportion, x = df['Description'], name = agents[i].capitalize(), marker = dict(color = colors[i]))
traces.append(currentTrace)
fig.update_layout(
legend_title_text='Agent',
yaxis_title='Proportion of Behaviors',
xaxis_title='Behavior: ' + behavior,
xaxis = dict(showticklabels=False),
title ='Behavior Grouped by Participant: ' + behavior,
width=900, height=600,
plot_bgcolor = 'white',
boxmode = 'group')
fig.add_traces(traces)
fig.update_yaxes(gridcolor='#D3D3D3')
return fig
#plot glance at others
fig = go.Figure()
traces = []
jibo = go.Box(y= allBehaviors[(allBehaviors["Agent"] == 'Jibo') & (allBehaviors["Description"] == 'Glance at Others')].Proportion, name = 'jibo',
marker = dict(color = 'rgb(238,166,101)'))
alexa = go.Box(y= allBehaviors[(allBehaviors["Agent"] == 'Alexa') & (allBehaviors["Description"] == 'Glance at Others')].Proportion, name = 'alexa',
marker = dict(color = 'rgb(238,199,188)'))
computer = go.Box(y= allBehaviors[(allBehaviors["Agent"] == 'Computer') & (allBehaviors["Description"] == 'Glance at Others')].Proportion, name = 'computer',
marker = dict(color = 'rgb(154,196,196)'))
traces.append(jibo)
traces.append(alexa)
traces.append(computer)
fig.add_traces(traces)
group_labels = ['J', 'A', 'C']
colors = ['rgb(238,166,101)', 'rgb(238,199,188)', 'rgb(154,196,196)', 'rgb(215,189,209)']
fig.show()
#across the three agents - glance at others
stats.f_oneway(allBehaviors[(allBehaviors["Agent"] == 'Jibo') & (allBehaviors["Description"] == 'Glance at Others')].Proportion,
allBehaviors[(allBehaviors["Agent"] == 'Alexa') & (allBehaviors["Description"] == 'Glance at Others')].Proportion,
allBehaviors[(allBehaviors["Agent"] == 'Computer') & (allBehaviors["Description"] == 'Glance at Others')].Proportion)
frames = [allBehaviors[(allBehaviors["Agent"] == 'Jibo') & (allBehaviors["Description"] == 'Glance at Others')],
allBehaviors[(allBehaviors["Agent"] == 'Alexa') & (allBehaviors["Description"] == 'Glance at Others')],
allBehaviors[(allBehaviors["Agent"] == 'Computer') & (allBehaviors["Description"] == 'Glance at Others')]]
glance = pd.concat(frames)
#model for glance at others
model = ols('Proportion ~ C(Agent)', data=glance).fit()
anova_table = sm.stats.anova_lm(model, typ=2)
anova_table
MultiComp = MultiComparison(glance['Proportion'],glance["Agent"])
print(MultiComp.tukeyhsd().summary())
print('Computer: ', statistics.mean(glance[(glance["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.mean(glance[(glance["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.mean(glance[(glance["Agent"] == "Alexa")].Proportion))
print('Computer: ', statistics.stdev(glance[(glance["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.stdev(glance[(glance["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.stdev(glance[(glance["Agent"] == "Alexa")].Proportion))
Combined Inter-Group Behaviors
frames = [allBehaviors[(allBehaviors["Agent"] == 'Jibo') & (allBehaviors["Description"] == 'Glance at Others')],
allBehaviors[(allBehaviors["Agent"] == 'Alexa') & (allBehaviors["Description"] == 'Glance at Others')],
allBehaviors[(allBehaviors["Agent"] == 'Computer') & (allBehaviors["Description"] == 'Glance at Others')],
allBehaviors[(allBehaviors["Agent"] == 'Jibo') & (allBehaviors["Description"] == 'Whisper')],
allBehaviors[(allBehaviors["Agent"] == 'Alexa') & (allBehaviors["Description"] == 'Whisper')],
allBehaviors[(allBehaviors["Agent"] == 'Computer') & (allBehaviors["Description"] == 'Whisper')],
allBehaviors[(allBehaviors["Agent"] == 'Jibo') & (allBehaviors["Description"] == 'Defend')],
allBehaviors[(allBehaviors["Agent"] == 'Alexa') & (allBehaviors["Description"] == 'Defend')],
allBehaviors[(allBehaviors["Agent"] == 'Computer') & (allBehaviors["Description"] == 'Defend')],
]
inter_group = pd.concat(frames)
inter_group
#plot inter-group
human = go.Figure()
humanTraces = []
jibo = go.Box(y= inter_group[(inter_group["Agent"] == 'Jibo')].Proportion, name = '<b>Jibo</b>',
marker = dict(color = 'rgb(238,166,101)'))
alexa = go.Box(y= inter_group[(inter_group["Agent"] == 'Alexa')].Proportion, name = '<b>Alexa</b>',
marker = dict(color = 'rgb(238,199,188)'))
computer = go.Box(y= inter_group[(inter_group["Agent"] == 'Computer')].Proportion, name = '<b>Computer</b>',
marker = dict(color = 'rgb(154,196,196)'))
humanTraces.append(jibo)
humanTraces.append(alexa)
humanTraces.append(computer)
human.add_traces(humanTraces)
group_labels = ['J', 'A', 'C']
colors = ['rgb(238,166,101)', 'rgb(238,199,188)', 'rgb(154,196,196)', 'rgb(215,189,209)']
human.update_layout(
legend_title_text='<b>Agent</b>',
title_text ='<b>Human-Human Interactions</b>' ,
width=800, height=800,
plot_bgcolor = 'white',
boxmode = 'group',
font=dict(
size=20,
color="#000000",
family="Calibri, Body",)
)
human.update_yaxes(gridcolor='#D3D3D3')
human.update(layout=dict(title=dict(x=0.5)))
human.show()
human.write_image("images/human.svg")
#across the three agents - inter_group
stats.f_oneway(inter_group[(inter_group["Agent"] == 'Jibo')].Proportion,
inter_group[(inter_group["Agent"] == 'Alexa')].Proportion,
inter_group[(inter_group["Agent"] == 'Computer')].Proportion)
anova_oneway(inter_group)
#model for inter group
model = ols('Proportion ~ C(Agent)', data=inter_group).fit()
anova_table = sm.stats.anova_lm(model, typ=2)
anova_table
MultiComp = MultiComparison(inter_group['Proportion'],inter_group["Agent"])
print(MultiComp.tukeyhsd().summary())
print('Computer: ', statistics.mean(inter_group[(inter_group["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.mean(inter_group[(inter_group["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.mean(inter_group[(inter_group["Agent"] == "Alexa")].Proportion))
print('Computer: ', statistics.stdev(inter_group[(inter_group["Agent"] == "Computer")].Proportion))
print('Jibo: ', statistics.stdev(inter_group[(inter_group["Agent"] == "Jibo")].Proportion))
print('Alexa: ', statistics.stdev(inter_group[(inter_group["Agent"] == "Alexa")].Proportion))
def plotBoxes(listofDFs):
nonempty = []
for df in listofDFs:
if list(df['Description']) != []:
label = list(df['Description'])[0]
nonempty.append(label)
current = makeBoxplot(df, label)
#Uncomment below to plot and store the output as .png
current.show()
# current.write_image("all/" + str(label) + ".png")
print("\n",label, "\n")
anova_oneway(df)
plotBoxes(singleBehaviorDFs)
# plotBoxes(singleBehaviorDFsP)
# plotBoxes(singleBehaviorDFsN)
# plotBoxes(singleBehaviorDFsM)
# plotBoxes(singleBehaviorDFsS)
#Will output one way ANOVA for all pairs of agents. Significant p-value results will be in purple.
def three_anova_oneway(dataframe1):
#combinations = list(itertools.combinations(agents, 2)) #Creates all pairwise combinations of agents (i.e. Alexa & Jibo, etc)
print(colored.fg("black") + "One Way ANOVAs:")
#for combo in combinations:
pvalString = ''
#run oneway anova here - will use the same dataframe passed in
oneway = stats.f_oneway(
dataframe1[(dataframe1["Agent"] == "Jibo")].Proportion, #Take first agent in pair
dataframe1[(dataframe1["Agent"] == "Alexa")].Proportion, #Take second agent in pair
dataframe1[(dataframe1["Agent"] == "Computer")].Proportion)
pval = oneway[1]
#just for printing the purple significant p-vals
if pval < 0.05:
pvalString = colored.fg("magenta_3a") + str(pval)
else:
pvalString = colored.fg("black") + str(pval)
resultstr = colored.fg("black") + " P-Value: " + pvalString
print(resultstr)
def plotThreeBoxes(listofDFs):
nonempty = []
for df in listofDFs:
if list(df['Description']) != []:
label = list(df['Description'])[0]
nonempty.append(label)
current = makeBoxplot(df, label)
#Uncomment below to plot and store the output as .png
# current.show()
# current.write_image("all/" + str(label) + ".png")
print("\n",label, "\n")
three_anova_oneway(df)
#plotThreeBoxes(singleBehaviorDFs)